// ignore_for_file: must_be_immutable

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:junyeyishu/utils/ScreenFit.dart';

import 'package:junyeyishu/widgets/QGWidget.dart';

class QGNavigationBar extends StatelessWidget {
  String? title;
  TextStyle? titleStyle;
  Widget? leftItem;
  Widget? rightItem;
  VoidCallback? onBack;
  QGNavigationBar(
      {super.key,
      this.title,
      this.leftItem,
      this.rightItem,
      this.onBack,
      this.titleStyle});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 56 + max(kSafeTop, 20),
      padding: EdgeInsets.only(top: max(kSafeTop, 20)),
      child: Stack(
        children: [
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  leftItem ??
                      GestureDetector(
                        onTap: () {
                          if (onBack != null) {
                            onBack!();
                          } else {
                            Navigator.of(context).pop();
                          }
                        },
                        child: Container(
                          padding: EdgeInsets.all(15.rpx),
                          child: QGImage(asset: "nav_back_white",width: 20.rpx),
                        ),
                      ),
                  rightItem ?? Container(),
                ]),
          ),
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            child: Visibility(
              visible: (title?.length ?? 0) > 0,
              child: Container(
                alignment: Alignment.center,
                child: Text(
                  title ?? "",
                  textAlign: TextAlign.center,
                  style: titleStyle ??
                      TextStyle(
                          color: Color(0xFFffffff),
                          fontSize: 15.rpx,
                          fontWeight: FontWeight.normal),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
